/*
 * @Author: szx
 * @Date: 2021-12-26 13:25:25
 * @LastEditTime: 2021-12-26 13:29:59
 * @Description:
 * @FilePath: \leetcode\100-199\108\108.js
 */
/**
 * @param {number[]} nums
 * @return {TreeNode}
 */
var sortedArrayToBST = function (nums) {
    const dfs = (left, right) => {
        if (left >= right) {
            return null;
        }
        const mid = Math.floor(left + right) / 2;
        const root = new TreeNode(nums[mid]);
        root.left = dfs(left, mid - 1);
        root.right = dfs(mid + 1, right);
        return root;
    };
    return dfs(0, nums.length - 1);
};
